package com.seocoo.worker.user;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.seocoo.worker.R;
import com.seocoo.worker.base.entity.EUserInfoBean;
import com.seocoo.worker.base.widget.AppToolBer;
import com.seocoo.worker.base.widget.MyProgressView;
import com.seocoo.worker.user.login.PlatformDialog;
import com.seocoo.worker.user.model.UserModel;
import com.sfh.lib.mvvm.LiveDataMatch;
import com.sfh.lib.ui.MVVMActivity;

/***
 * 我的等级
 */
public class UserGradeActivity extends MVVMActivity {
    private AppToolBer appToolBer;
    private TextView tvIntegral;
    private TextView tvLevel;
    private MyProgressView progressBar;

    public static void start(Context context) {
        Intent intent = new Intent(context, UserGradeActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_grade_activity);
        initView();
        StatusBarUtil.setTransparentForImageView(this,  appToolBer);
        getViewModel(UserModel.class).getUserInfo();
    }

    private void initView() {
        appToolBer = (AppToolBer) findViewById(R.id.appToolBer);
        tvIntegral = (TextView) findViewById(R.id.tv_integral);
        tvLevel = (TextView) findViewById(R.id.tv_level);
        progressBar = (MyProgressView) findViewById(R.id.progressBar);
        findViewById(R.id.ll).setOnClickListener(v -> UserIntegralActivity.start(UserGradeActivity.this));
        appToolBer.getTvRight().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getViewModel(UserModel.class).queryRule("2");
            }
        });
        appToolBer.getTvRight().setVisibility(View.GONE);
        getViewModel(UserModel.class).queryRuleShow("2");
    }
    @LiveDataMatch
    public void showRuleIcon(){
        appToolBer.getTvRight().setVisibility(View.VISIBLE);
    }

    @LiveDataMatch
    public void showRule(String msg){
        PlatformDialog.showDialogUI(this,"工匠升级规则",msg);
    }

    @LiveDataMatch
    public void onUserInfo(EUserInfoBean infoBean) {
        if (infoBean == null) {
            return;
        }
        progressBar.setProgress(infoBean.getIntegral());
        tvIntegral.setText(infoBean.getIntegral()+"");
        tvLevel.setText(infoBean.getCraftsmanLevel()+"匠人");

    }
}
